<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="ljc">
    <title></title>
    <script src="jquery-3.1.1.js">
        
    </script>
    <style>
        div{
            width: 400px;
            margin: 0px auto;
            position: relative;
        }
        span{
            width: 100px;
            display: inline-block;
            padding: 10px;
            background-color: lawngreen;
            font-size: 20px;
            text-align: center;
        }
        span:nth-of-type(2){
            width: 200px;
            background-color: lightgrey;
        }
        ul{
            margin: 0;
            list-style: none;
              position: absolute;
            left:120px;
            width: 220px;
            border:1px solid red;
            box-sizing: border-box;
            padding: 0;
            text-align: center;
            display: none;
        }
        li{
            height: 40px;
            width: 100%;
            border-bottom: 1px dotted red;
        }
    </style>
</head>
<body>
    <div>
        
    
    <span>选择项目:</span><span>未选择</span>
    <ul>
        <li>html5</li>
        <li>css3</li>
        <li>javascript</li>
        <li>jquery</li>
    </ul>
    
    </div>
</body>
</html>
<script>
    $($('span')[1]).mouseover(function(){
        $('ul').css('display','block');
        $('li').each(function(index){
            $(this).mouseover(function(){

                $(this).css('backgroundColor','gray').siblings().css('backgroundColor','white');
            })
            $(this).mouseleave(function(){
                $('li').css('backgroundColor','white');
            })
            $(this).mousedown(function(){
                $($('span')[1]).html($(this).html());
                $('ul').css('display','none');
            })
        })
    })
</script>
